package com.dsg.workflow;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsg.common.util.SingletonLoginUtils;
import com.dsg.common.util.toolbox.StringUtil;
import com.dsg.entity.account.DsgAccountCard;
import com.dsg.entity.account.DsgAccountTrade;
import com.dsg.entity.apply.DsgApplyBill;
import com.dsg.entity.apply.DsgApplyCar;
import com.dsg.entity.approve.DsgApproveCase;
import com.dsg.service.account.IDsgAccountCardService;
import com.dsg.service.account.IDsgAccountTradeService;
import com.dsg.service.apply.IDsgApplyCarService;
import com.dsg.service.apply.IDsgApplyCusService;
import com.dsg.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

/**
 * 現金咭新申請
 */
@Service
public class WorkflowService21 extends AbstractWorkflowService {

    @Autowired
    IDsgApplyCarService carService;
    @Autowired
    IDsgApplyCusService cusService;

    @Override
    protected String recalculateNodeName(DsgApplyBill bill) {
        return NODE_INPUT_CAR_INFO;
    }

    @Override
    protected boolean canGoOn(DsgApplyBill bill) throws Exception {
        boolean carAudit = carService.carAuditAll(bill);
        boolean cusAudit = cusService.audit(bill);
        return carAudit && cusAudit;
    }

    @Override
    protected Set getConditionalNodeSet(DsgApplyBill bill) {
        Set<String> conditionalNodeSet = new HashSet<>();
        conditionalNodeSet.add(NODE_CHECK_LIST);
        return conditionalNodeSet;
    }

    @Override
    protected boolean needNode(String currNodeName, DsgApplyBill bill, String nodeName) {
        switch (nodeName) {
            case NODE_CHECK_CAR_NO:
                if (!isHKCar(bill))
                    return false;
                break;
        }
        return true;
    }

    /**
     * 是否中港車
     */
    private boolean isHKCar(DsgApplyBill bill) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("MAIN_NO", bill.getMainNo());
        wrapper.eq("APP_NO", bill.getAppNo());
        wrapper.eq("CAR_IS_HK", DsgApplyCar.CAR_IS_HK_Y);
        if (carService.count(wrapper) > 0) {
            return true;
        } else {
            return false;
        }
    }
}
